package com.mapapp.flutter_mapapp.adapter;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mapapp.flutter_mapapp.R;
import com.mapapp.flutter_mapapp.bean.MyTaskBean;
import com.mapapp.flutter_mapapp.util.ImageUtil;

import java.util.List;

public class MyTaskAdapter extends BaseQuickAdapter<MyTaskBean, BaseViewHolder> {


    public MyTaskAdapter(int layoutResId, @Nullable List<MyTaskBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, MyTaskBean item) {
        TextView tvCount = helper.getView(R.id.tv_count);
        TextView tvTaskType = helper.getView(R.id.tv_task_type);
        ImageView ivIcon = helper.getView(R.id.iv_icon);
        LinearLayout llCount = helper.getView(R.id.ll_count);
        View divideBottom = helper.getView(R.id.divide_bottom);
        View divideTop = helper.getView(R.id.divide_top);

        ImageUtil.loadImage(item.getSrcId(), ivIcon);
        if (item.isCanClick()) {
            llCount.setVisibility(View.VISIBLE);
            tvTaskType.setTextColor(Color.parseColor("#3E3E3E"));
        } else {
            llCount.setVisibility(View.INVISIBLE);
            tvTaskType.setTextColor(Color.parseColor("#CCCCCC"));
        }

        divideTop.setVisibility(getData().indexOf(item) == 0 ? View.VISIBLE : View.GONE);
        divideBottom.setVisibility(getData().indexOf(item) == getItemCount() - 1 ? View.VISIBLE : View.GONE);

        tvTaskType.setText(item.getItemName());

        if (item.getCount() > 0) {
            tvCount.setText(String.valueOf(item.getCount()));
            tvCount.setVisibility(View.VISIBLE);
        } else {
            tvCount.setText("");
            tvCount.setVisibility(View.GONE);
        }

    }
}
